
<template>
    <div class="app-container">
      <!--工具栏-->
      <div class="head-container">
        <div v-if="crud.props.searchToggle" >
          <!-- 搜索 -->
          <el-form label-width="70px" size="small">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startBusDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endBusDate"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
              </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="部门">
                <!-- <TreeSelect
                  v-model="query.deptIds"
                  :options="depts"
                  placeholder="选择部门"
                  style="width:  100%"
                  :normalizer="normalizer"
                /> -->
                <zSelect :value.sync="query.deptIds" url="api/dropDown/childSysDeptList" style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="人员">
                <zSelect :value.sync="query.userIds" url="api/dropDown/sysUserList" style="width:  100%;"/>
              </el-form-item>
            </el-col>
            <rrOperation :crud="crud"/>
          </el-row>
        </el-form>

        </div>

        <crudOperation :permission="permission">
            <el-button type="primary" size="mini" class="btn" @click="manager(crud.selections)" slot="right" :disabled="crud.selections.some(item=>item.status===4)">经理审核</el-button>
        <el-button type="primary" size="mini" class="btn" @click="reject(crud.selections)" slot="right" :disabled="crud.selections.some(item=>item.status===1)">反审</el-button>
          <el-button
            slot="right"
            :loading="crud.downloadLoading"
            class="filter-item"
            size="mini"
            type="warning"
            @click="doExport"
          >导出</el-button>
        </crudOperation>
      </div>

      <div class="body-container">

        <vue-context-menu :contextMenuData="contextMenuData"
                          @tableConfig="tableConfig"
                          @deletedata="deletedata"></vue-context-menu>
        <!-- 表格配置 -->
        <el-dialog title="表格配置"
                   :visible.sync="tableConfigShow"
                   width="60%">
          <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
        </el-dialog>

        <!--表格渲染-->
        <el-table ref="table" stripe border
                  @cell-dblclick="row=>crud.toEdit(row)"
                  v-loading="crud.loading"
                  :data="crud.data"
                  size="small"
                  style="width: 100%;"
                  v-if="isShowTable"
                  @header-dragend="changeColWidth"
                  @contextmenu.native="showMenu"
                  @selection-change="crud.selectionChangeHandler">
            <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
            <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
            <el-table-column :render-header="crud.renderHeader" prop="code" label="编码"/>
            <el-table-column :render-header="crud.renderHeader" prop="deptName" label="部门"/>
            <el-table-column :render-header="crud.renderHeader" prop="busDate" label="业务日期"/>
            <el-table-column :render-header="crud.renderHeader" prop="beginTime" label="出差开始日期"/>
            <el-table-column :render-header="crud.renderHeader" prop="endTime" label="出差结束日期"/>
            <el-table-column :render-header="crud.renderHeader" prop="days" label="出差天数"/>
            <el-table-column :render-header="crud.renderHeader" prop="reason" label="请假原因"/>
            <el-table-column :render-header="crud.renderHeader" prop="status" label="状态">
            <template slot-scope="scope">
                {{ dict.label.dict_process_status[scope.row.status] }}
            </template>
            </el-table-column>
            <el-table-column :render-header="crud.renderHeader" prop="passUserName" label="审批人"/>
            <el-table-column :render-header="crud.renderHeader" prop="notifyUserList" label="抄送人">
            <template slot-scope="scope">
                <span v-for="(item,i) in scope.row.notifyUserList" :key="i">
                {{item.notifyUserName}},
                </span>
            </template>
            </el-table-column>

        </el-table>
        <!--分页组件-->
        <pagination/>
      </div>
    </div>
  </template>

  <script>
    import CRUD, {crud, form, header, presenter} from '@crud/crud';
    import rrOperation from '@crud/RR.operation';
    import crudOperation from '@crud/CRUD.operation';
    import udOperation from '@crud/UD.operation';
    import pagination from '@crud/Pagination';
    import { publicListKey } from "@/utils/key";
    import {tablemixins} from "@/mixins/tablemixins";
    import { getToken } from '@/utils/auth';
    import {managerPass,reject} from '@/api/erp/askForLeave'
    import {downloadFile} from "@/utils";
    import {download} from "@/api/data";
  const defaultCrud = CRUD({
    title: '出差', url: 'api/appAskForLeave/queryAll',  sort: 'id,asc', crudMethod: {},
    optShow: {
      add: false,
      edit: false,
      del: false,
    },
    props: {
      tableColumns:['checkedUserCode','checkedUserName']
    },
    query:{
        type:'2'
    }
  })
  const defaultForm = {
    beginTime: null,
    endTime: null,
    busDate:null,
    type: '',
    reason: '',

  }
  export default {
    name: 'evection',
    components: {pagination, crudOperation, rrOperation, udOperation,},
    mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
    dicts: ["dict_process_status",'dict_rest_type'],
    data() {
      return {
        headers: { Authorization: getToken() },
        permission: {
          add: ['admin', 'evection:add'],
        },
      }
    },
    watch: {},
    created() {

    },
    updated() {
      this.$nextTick(() => {
        this.$refs.table.doLayout()
      })
    },
    methods: {
      manager(val){
        const data=val.map(item=>{
        return item.id
        })
        managerPass(data).then(res=>{
          this.crud.refresh()
          this.$message({
              message: res.msg,
              type: 'success'
            });
        })
      },
      doExport(){
        this.crud.downloadLoading = true
        download('api/askForLeave/export', this.crud.getQueryParams(),this.crud.queryType).then(result => {
          downloadFile(result, this.crud.title + '数据', 'xlsx')
          this.crud.downloadLoading = false
        }).catch(() => {
          this.crud.downloadLoading = false
        })
      },
      reject(val){
        const data=val.map(item=>{
        return item.id
        })
        reject(data).then(res=>{
          this.crud.refresh()
          this.$message({
              message: res.msg,
              type: 'success'
            });
        })
      },
      // 获取数据前设置好接口地址
      [CRUD.HOOK.beforeRefresh]() {
        return true
      }, // 新增与编辑前做的操作
      [CRUD.HOOK.afterToCU](crud, form) {
      },
    }
  }
  </script>

  <style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  </style>
